package cn.com.io.file;

import java.io.File;
import java.io.FilenameFilter;

/**
 * Created by Administrator on 2015/12/9.
 */

/**
 * 文件过滤器
 * 这里使用FilenameFilter，原FileFilter也是实现FilenameFilter类
 */
public class FileFilterTest {
    public static void main(String[] args) {
        File file = new File(".");
        String[] list = file.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".java") || new File(name).isDirectory();//列出JAVA文件以及文件夹
            }
        });
        for (String str : list){
            System.out.println(str);
        }
    }
}
